//
//  RankingVC.m
//  timelyRain
//
//  Created by Jiafei Wei on 16/9/5.
//  Copyright © 2016年 Jiafei Wei. All rights reserved.
//

#import "RankingVC.h"
#import "TimeHeader.h"
#import "HttpTool.h"
#import "WalkRank.h"
#import "WalkRankBase.h"
#import "RankCell.h"
#import "RankHead.h"
#import "RankFooter.h"
#import "WalkShareVC.h"
@interface RankingVC ()<TimeHeaderDelegate,UITableViewDelegate,UITableViewDataSource,RankFooterDelegate>
{
    NSMutableArray *walkData;
}
@property (weak, nonatomic) IBOutlet UIView *titleView;

@property (weak, nonatomic) IBOutlet UITableView *table;
@end

@implementation RankingVC

- (void)viewDidLoad {
    [super viewDidLoad];
    walkData = [NSMutableArray array];
    WalkRank *rang =[[WalkRank alloc]init];
    rang.rank =@"99999";
    rang.user_id =@"99999";
    rang.nickname =@"99999";
    rang.head_pic =@"99999";
    rang.step =@"99999";
    [walkData addObject:rang];
    _table.delegate =self;
    self.navigationController.navigationBarHidden=YES;
    TimeHeader *head =[TimeHeader headerView];
    head.delegate =self;
    [_titleView addSubview:head];
    [self getRank];
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    RankCell *cell =  [RankCell setRankCellWithTableView:tableView];
    WalkRank *info = walkData[indexPath.row];
    cell.info =info;
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return walkData.count;
}

-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    RankFooter *foot = [RankFooter footerView];
    foot.delegate =self;
    if (walkData.count==0) {
        foot.hidden=YES;
    }
    return foot;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 50;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    RankHead *head =[RankHead headerView];
    head.rankText.text=@"哈哈哈";
    return head;
}
-(void)share{
    WalkShareVC *share =[[WalkShareVC alloc]init];
    [self.navigationController pushViewController:share animated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}
-(void)back{
    [self.navigationController popViewControllerAnimated:YES];
}
-(void)right{

}

-(void)getRank{//只需要一id
    [HttpTool GET:@"http://www.aiaiaini.com/demo/web/index.php?r=api/step/get-walk-rank" WithHeader:NO parameters:nil success:^(id responseObject) {
        WalkRankBase *data =[WalkRankBase mj_objectWithKeyValues:responseObject];
        if (data.status) {
            WalkRankInfo *info =data.data;
            [walkData addObjectsFromArray:info.data];//插入数据
            [_table reloadData];
        }else{
            
        }
    } failure:^(NSError *error){
        NSLog(@"%@",error);
    }];
}
@end
